import type { CarCostVO, CarCostForm, CarCostQuery } from './model';

import type { ID, IDS } from '#/api/common';
import type { PageResult } from '#/api/common';

import { commonExport } from '#/api/helper';
import { requestClient } from '#/api/request';

/**
 * 查询车辆费用列表
 * @param params
 * @returns 车辆费用列表
 */
export function carCostList(params?: CarCostQuery) {
  return requestClient.get<PageResult<CarCostVO>>('/trade/carCost/list', {
    params,
  });
}

/**
 * 导出车辆费用列表
 * @param params
 * @returns 车辆费用列表
 */
export function carCostExport(params?: CarCostQuery) {
  return commonExport('/trade/carCost/export', params ?? {});
}

/**
 * 查询车辆费用详情
 * @param orderId orderId
 * @returns 车辆费用详情
 */
export function carCostInfo(id: ID) {
  return requestClient.get<CarCostVO>(`/trade/carCost/${id}`);
}

/**
 * 查询车辆费用详情
 * @param orderId orderId
 * @returns 车辆费用详情
 */
export function carCostInfoByOrderId(orderId: ID) {
  return requestClient.get<CarCostVO>(
    `/trade/carCost/getInfoByOrderId/${orderId}`,
  );
}

/**
 * 新增车辆费用
 * @param data
 * @returns void
 */
export function carCostAdd(data: CarCostForm) {
  return requestClient.postWithMsg<void>('/trade/carCost', data);
}

/**
 * 更新车辆费用
 * @param data
 * @returns void
 */
export function carCostUpdate(data: CarCostForm) {
  return requestClient.putWithMsg<void>('/trade/carCost', data);
}

/**
 * 删除车辆费用
 * @param id id
 * @returns void
 */
export function carCostRemove(id: ID | IDS) {
  return requestClient.deleteWithMsg<void>(`/trade/carCost/${id}`);
}

/**
 * 作废
 * @param data 包含id
 * @returns void
 */
export function carCostInvalidate(data: { id: ID}) {
  return requestClient.postWithMsg<void>(`/trade/carCost/invalidate`, data);
}

/**
 * 车辆费用提交审核
 * @param data ids
 * @returns void
 */
export function carCostSubmit(data: IDS) {
  return requestClient.post<void>(`/trade/carCost/submit`, data);
}

/**
 * 车辆费用审核
 * @param id id
 * @param passed 是否通过
 * @param rejectReason 拒绝理由
 * @returns void
 */
export function carCostApprove(id: ID, passed: boolean, rejectReason?: string) {
  return requestClient.postWithMsg<void>(`/trade/carCost/approve`, {
    id: id,
    passed: passed,
    rejectReason: rejectReason,
  });
}
